package br.ufpb.di.knowledgetv.sqtv.modules;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import br.ufpb.di.knowledgetv.sqtv.utils.Data;

@Component
public class WorkflowModule {

    @Autowired
    private MetadataReceiverModule metadataReceiverModule;
    @Autowired
    private LinkedDataSearchModule linkedDataSearchModule;
    @Autowired
    private SemanticEnrichmentModule semanticEnrichmentModule;
    @Autowired
    private ResultAlignmentModule resultAlignmentModule;
    @Autowired
    private SaveInstanceModule saveInstanceModule;
    @Autowired
    private  LocalSearchModule localSearchModule;
    @Autowired
    private ProcessResponseModule processResponseModule;

    public WorkflowModule() {
    }


    public Data start(String request) {
        Data data = new Data();
        data.addData("keywords", request);
        this.metadataReceiverModule.execute(data);
        this.localSearchModule.execute(data);
        if (data.hasData("local_results")) {
            this.processResponseModule.execute(data);
        } else {
            this.linkedDataSearchModule.execute(data);
            this.semanticEnrichmentModule.execute(data);
            this.resultAlignmentModule.execute(data);
            this.saveInstanceModule.execute(data);
            this.localSearchModule.execute(data);
            this.processResponseModule.execute(data);
        }
        return data;
    }
}